//
//  ZYStatuserCell.m
//  山寨微博
//
//  Created by 张亚 on 16/1/20.
//  Copyright © 2016年 zhangya. All rights reserved.
//

#import "ZYStatuserCell.h"
#import "ZYStatuse.h"
#import "ZYStatusFrame.h"

#define NAMEVIEW_FONT [UIFont systemFontOfSize:15]

@interface ZYStatuserCell ()

@property (nonatomic,weak) UIImageView * iconView;
@property (nonatomic,weak) UILabel * nameView;
@property (nonatomic,weak) UIImageView * vipView;
@property (nonatomic,weak) UILabel * textView;
@property (nonatomic,weak) UIImageView * pictureView;

@end


@implementation ZYStatuserCell
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString * cellID = @"cell";
    ZYStatuserCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ZYStatuserCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //头像
        UIImageView * iconView = [[UIImageView alloc]init];
        [self.contentView addSubview:iconView];
        self.iconView = iconView;
        //昵称
        UILabel * nameView = [[UILabel alloc]init];
        nameView.font = NAMEVIEW_FONT;
        [self.contentView addSubview:nameView];
        self.nameView = nameView;
        
        UIImageView * vipView = [[UIImageView alloc]init];
        [self.contentView addSubview:vipView];
        self.vipView = vipView;
        
        UILabel * textView = [[UILabel alloc]init];
        textView.numberOfLines = 0;
        textView.font = NAMEVIEW_FONT;
        [self.contentView addSubview:textView];
        self.textView = textView;
        
        UIImageView * pictureView = [[UIImageView alloc]init];
        [self.contentView addSubview:pictureView];
        self.pictureView = pictureView;
        
    }
    return self;
}
#pragma mark ----- 设置cell的模型数据

- (void)setStatusFrame:(ZYStatusFrame *)statusFrame{

    _statusFrame = statusFrame;
    //给cell设置数据
    [self settingData];
    //给cell设置尺寸
    [self settingFrame];
    
}

- (void)settingData{
    
    ZYStatuse * status = self.statusFrame.status;
    //头像
    self.iconView.image = [UIImage imageNamed:status.icon];
    //昵称
    self.nameView.text = self.statusFrame.status.name;
    //会员图标
    if (status.vip) {
        self.vipView.hidden = NO;
        self.nameView.textColor = [UIColor redColor];
        self.vipView.image = [UIImage imageNamed:@"vip"];
    }else{
        self.nameView.textColor = [UIColor blackColor];
        self.vipView.hidden = YES;
    }
    //正文
    self.textView.text = self.statusFrame.status.text;
    //配图
    if (status.picture) {
        self.pictureView.hidden = NO;
        self.pictureView.image = [UIImage imageNamed:status.picture];
    }else{
        self.pictureView.hidden = YES;
    }
}

- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize{
    NSDictionary *  attrs = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}


- (void)settingFrame{
    
//    self.iconView.frame = self.statusFrame.iconF;

//    //昵称
//    self.nameView.frame = self.statusFrame.nameF;
//    
//    //会员图标
//    self.vipView.frame = self.statusFrame.vipF;
    
    //正文
    self.textView.frame = self.statusFrame.textF;
    
    //配图
    if (self.statusFrame.status.picture) {

        self.pictureView.frame = self.statusFrame.pictureF;
 
    }

}

@end
